﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Empires.Infrastructure.Entities.Repository;
using Empires.Infrastructure.Entities.Enum;

namespace Empires.Infrastructure.Entities.Entity
{
    public class Corporation : IAccessible<T_Corporation, Corporation>, ILogicEntity<T_Corporation, Corporation>
    {
        public string Master { get; set; }
        /// <summary>
        /// 站点名
        /// </summary>
        public string SiteName { get; set; }
        public string Logo { get; set; }
        public string Description { get; set; }
        public AreaCode Area { get; set; }
        public Location Location { get; set; }
        /// <summary>
        /// 所属行业
        /// </summary>
        public Industry Industry { get; set; }
        public string CorporationName { get; set; }
        /// <summary>
        /// 缩写，用于建立二级域名
        /// </summary>
        public string ShortName { get; set; }
        /// <summary>
        /// 公司联系电话
        /// </summary>
        public string CopPhone { get; set; }
        /// <summary>
        /// 公司地址
        /// </summary>
        public string CopAddress { get; set; }
        /// <summary>
        /// 公司联系人
        /// </summary>
        public string CopContact { get; set; }
        /// <summary>
        /// ICP号
        /// </summary>
        public string ICP { get; set; }
        /// <summary>
        /// 所启用模板Id
        /// </summary>
        public int TempId { get; set; }

        protected override void Covariant(T_Corporation model)
        {
            if (model != null)
            {
                this.Description = model.Description;
                this.Industry = (Enum.Industry)model.Industry;
                this.Logo = model.Logo;
                this.Master = model.Master;
                this.SiteName = model.SiteName;
                this.Area = (AreaCode)model.Area;
                this.Location = (Location)model.Location;
                this.CopAddress = model.CopAddress;
                this.CopContact = model.CopContact;
                this.CopPhone = model.CopPhone;
                this.ICP = model.ICP;
                this.CorporationName = model.CorporationName;
                this.TempId = model.TempId;
                this.ShortName = model.ShortName;
            }
        }

        protected override T_Corporation Inverter(Corporation model)
        {
            if (model != null)
            {
                return new T_Corporation()
                {
                    Description = model.Description,
                    Industry = (int)model.Industry,
                    Logo = model.Logo,
                    Master = model.Master,
                    SiteName = model.SiteName,
                    Area = (int)model.Area,
                    Location = (int)model.Location,
                    CopAddress=model.CopAddress,
                    CopContact=model.CopContact,
                    CopPhone=model.CopPhone,
                    CorporationName=model.CorporationName,
                    ICP=model.ICP,
                    TempId=model.TempId,
                    ShortName = model.ShortName
                };
            }
            return null;
        }

        public Corporation Set(T_Corporation dbModel)
        {
            Covariant(dbModel);
            return this;
        }
    }
}
